/*
 * InputParser.cpp
 *
 *  Created on: 2012-04-22
 *      Author: mm
 */

#include "InputParser.h"
#include <iostream>

InputParser* InputParser::instance_ = 0L;

InputParser::Tokens InputParser::parseLine(const std::string& line)
{
	bool bracketsOpen = false;
	InputParser::Tokens tokens;
	std::string token;
	std::string temp;

	token.clear();
	temp.clear();

	for(std::string::size_type i = 0; i < line.length(); ++i )
	{
			switch (line[i])
			{
				case '=':
				case ',':
					tokens.push_back(token);
					token.clear();
					break;

				case ']':
					bracketsOpen = false;
					tokens.push_back(token);
					tokens.push_back("]");
					token.clear();
					break;

				case '[':
					bracketsOpen = true;
					if(!token.empty())
						tokens.push_back(token);
					tokens.push_back("[");
					token.clear();
					break;

				case ' ':
					if(bracketsOpen)
					break;

				default:
					token += line[i];
			}
	}

	if(!token.empty())
		tokens.push_back(token);

	return tokens;
}
